package com.example.backend.service.impl;

import com.example.backend.mapper.OrderMapper;
import com.example.backend.mapper.RestaurantMapper;
import com.example.backend.mapper.ReviewMapper;
import com.example.backend.pojo.Review;
import com.example.backend.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReviewServiceImpl implements ReviewService {
    @Autowired
    private ReviewMapper reviewMapper;
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestaurantMapper restaurantMapper;
    @Override
    public List<Review> getallbyuserid(Integer userid) {
        return reviewMapper.getallbyuserid(userid);
    }


    @Override
    public List<Review> getallbyresid(Integer resid) {
        return reviewMapper.getallbyresid(resid);
    }

    @Override
    public void addreview(Review review) {
        reviewMapper.addreview(review);
        orderMapper.updatereview(review.getReviewid(),review.getOrderid());
        Float avgpoint = reviewMapper.avgpoint(review.getOrderid());
        restaurantMapper.updatepoint(avgpoint,review.getOrderid());
    }

    @Override
    public void reply(Integer reviewid, String reply) {
        reviewMapper.reply(reviewid, reply);
    }
    @Override
    public Review getByid(Integer reviewid) {
        return  reviewMapper.getByid( reviewid);
    }
}
